{include file="public_head"}
<style>
    .sign_icon {
        font-size: 16px;
        line-height: 24px;
        margin-right: 20px;
        margin-top: 17px;
        color: #EF2131;
    }
    .sign_icon img {
        margin-top: -3px;
        margin-right: 10px;
    }
</style>
{include file="public_menu"}
    <div class="content_center">
        <div class="main_center">
            {include file="public_information_menu"}
            <div class="main_right right">
                <div class="main_right_title">积分兑换
                    {if condition="$check_sign eq 'signIn'"}
                    <div class="right sign_icon"><img src="__STATIC__/img/icon81.png">已签到</div>
                    {else/}
                    <div class="right sign_icon" onclick="sign()"><img src="__STATIC__/img/icon81.png">每日签到</div>
                    {/if}
                </div>
                <div class="main_integral">
                    <div class="tabList">
                        <ul>
                            <!--{eq name=":input('orderId')" value="" }class="primary"{/eq}-->
                            <li {eq name=":input('orderId')" value="" }class="primary active"{/eq}><a href="javascript:set_sort(' ');">排序：默认</a></li>
                            <li {eq name=":input('orderId')" value="surplus" }class="primary active"{/eq}><a href="javascript:set_sort('number');">领取数</a></li>
                            <li {eq name=":input('orderId')" value="market_price" }class="primary active"{/eq}><a href="javascript:set_sort('market_price');"><span>价格</span></a></li>
                            <li {eq name=":input('orderId')" value="price" }class="primary active"{/eq}><a href="javascript:set_sort('price');"><span>积分数</span></a></li>
                        </ul>
                    </div>
                    <div class="tabCon">
                        <div class="cur">
                            <ul class="list-group">
                                {volist name="integral_goods" id="item"}
                                <li>
                                    <div class="pic">
                                        <a href="#">
                                            <img src="/{$item.thumb_img}">
                                        </a>
                                    </div>
                                    <div class="det">
                                        <h4>{$item.title|reStrLen=###,16}</h4>
                                        <del>市场价:{$item.market_price}</del>
                                        <span>积分：{$item.price}</span>
                                        <div><a href="javascript:exchange({$item.id},{$item.price});">兑换</a></div>
                                    </div>
                                </li>
                                {/volist}
                            </ul>
                        </div>
                        <div class="pages">{$integral_goods->render()}</div>
                    </div>
                </div>
                <input type="hidden" id="notes" value="{$integral['integral']}">
            </div>
        </div>
    </div>
<script>
    //执行兑换
    function exchange(id,price){
        var member = "{$Think.session.member_id}";
        if (!member) {
            layer.msg('用户未登录！请先登录！');
            window.location.href="{:url('shop/login/index')}";
            return ;
        }else {
            var integral = parseInt($('#notes').val());

            if (integral < price){
                layer.msg('积分不足换取此商品');
                return ;
            }else{
                window.location.href = "{:url('shop/integral/exchange')}?goods_id="+id;
            }
        }

    }
    
    
    //签到
    function sign() {
        $.ajax({
            url: "{:url('IntegralGoods/member_sign')}",
            type: 'post',
            dateType: 'json',
            data: {'member_id': "{$Think.session.member_id}"},
            success: function (t) {
                if (t.code == 200) {
                    layer.msg('签到成功');
                    location.reload();
                } else {
                    layer.msg(t.message);
                }

            }
        })
    }

    //商品排序
    function set_sort(parameter) {
        var url = "{:url('shop/integral_goods/index')}?&orderId="+parameter;
        window.location.href=url;

    }
   $(function () {
       $(".main_integral .tabList ul li").click(
               function () {
                   $(this).addClass("active").siblings().removeClass("active");
               }
       )
   })
</script>
{include file="public_foot"}